package cn.schoolwow.util.test.module.query.resource.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.resource.QueryResource;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.junit.Assert;

public class GetAsJSONArrayTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        JSONArray userArray = QueryResource.newQuery("用户数组","module/query/resource/userArray.json")
                .execute()
                .getAsJSONArray();
        Assert.assertEquals(1, userArray.size());
        JSONObject user = userArray.getJSONObject(0);
        Assert.assertEquals("zhangsan", user.getString("username"));
        Assert.assertEquals("123456", user.getString("password"));
    }

    @Override
    public String name() {
        return "读取资源文件并返回JSONArray测试用例";
    }
}
